package org.ume.school.modules.acticles;

import org.ume.school.modules.model.entity.Goods;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.QueryHints;

import javax.persistence.QueryHint;
import java.util.List;

/**
 * Created by Django on 2017/7/22.
 */
public interface ArticleRepository extends JpaRepository<Goods, String> {

    @QueryHints(value = {@QueryHint(name = "name", value = "value")},
            forCounting = true)
    public Page<Goods> findByTypeAndStatus(String type, Integer status,Pageable pageable);

    @Modifying
    @Query(value = "update Goods set greats=greats+1 where id=?1")
    public Integer thumbUp(String articleId);

    @Modifying
    @Query(value = "update Goods set commentCnt=commentCnt+1 where id=?1")
    public Integer commentUp(String articleId);

    List<Goods> findByUserId(String userId);

    @QueryHints(value = {@QueryHint(name = "name", value = "value")},
            forCounting = true)
    public Page<Goods> findByUserId(String userId, Pageable pageable);

    @Query(value = "select * from vshop_goods_storehouse where status = 1 order by greats desc limit 12", nativeQuery = true)
    List<Goods> findExcellents();
}
